﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Prisa.UI.Reportes;

namespace Prisa.UI
{
    public partial class MENU : Form
    {
        public MENU()
        {
            InitializeComponent();
            this.BuildUp();
        }
     
        float f_HeightRatio = new float();
        float f_WidthRatio = new float();

        public void ResizeForm(Form ObjForm, int DesignerHeight, int DesignerWidth)
        {
            #region Code for Resizing and Font Change According to Resolution
            
            int i_StandardHeight = DesignerHeight;
            int i_StandardWidth = DesignerWidth;
            int i_PresentHeight = Screen.PrimaryScreen.Bounds.Height;
            int i_PresentWidth = Screen.PrimaryScreen.Bounds.Width;
            f_HeightRatio = (float)((float)i_PresentHeight / (float)i_StandardHeight);
            f_WidthRatio = (float)((float)i_PresentWidth / (float)i_StandardWidth);
            ObjForm.AutoScaleMode = AutoScaleMode.None;
            ObjForm.Scale(new SizeF(f_WidthRatio, f_HeightRatio));
            foreach (Control c in ObjForm.Controls)
            {
                if (c.HasChildren)
                {
                    ResizeControlStore(c);
                }
                else
                {
                    c.Font = new Font(c.Font.FontFamily, c.Font.Size * f_HeightRatio, c.Font.Style, c.Font.Unit, ((byte)(0)));
                }
            }
            ObjForm.Font = new Font(ObjForm.Font.FontFamily, ObjForm.Font.Size * f_HeightRatio, ObjForm.Font.Style, ObjForm.Font.Unit, ((byte)(0)));
            #endregion
        }
 
        private void ResizeControlStore(Control objCtl)
        {
            #region

            if (objCtl.HasChildren)
            {
                foreach (Control cChildren in objCtl.Controls)
                {
                    if (cChildren.HasChildren)
                    {
                        ResizeControlStore(cChildren);
                    }
                    else
                    {
                        cChildren.Font = new Font(cChildren.Font.FontFamily, cChildren.Font.Size * f_HeightRatio, cChildren.Font.Style, cChildren.Font.Unit, ((byte)(0)));
                    }
                }
                objCtl.Font = new Font(objCtl.Font.FontFamily, objCtl.Font.Size * f_HeightRatio, objCtl.Font.Style, objCtl.Font.Unit, ((byte)(0)));
            }
            else
            {
                objCtl.Font = new Font(objCtl.Font.FontFamily, objCtl.Font.Size * f_HeightRatio, objCtl.Font.Style, objCtl.Font.Unit, ((byte)(0)));
            }
            #endregion
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
            //this.ResizeForm(this, 768, 1366); 
            TIMER.Start();
            //lblHora.Text = "" + DateTime.Now.ToLongDateString();
            
            
            var dia = DateTime.Now.Day;

            if (dia == 15)
            {
                var rpt = MessageBox.Show(this, string.Format("¿Desea ver el reporte de deudores?"), "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (rpt == DialogResult.Yes)
                {
                    var frm = new frmReporteDeudores();
                    frm.MdiParent = this;
                    frm.Show();
                }
            }
        }

        #region MENUS
        private void CONSULTASToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmProducto frm = new frmProducto();
            frm.MdiParent = this;
            frm.Show();
        }

        private void BuscarVentasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmVenta frm = new frmVenta();
            frm.MdiParent = this;
            frm.Show();
        }

        private void registrarVentaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmMttoVenta frm = new frmMttoVenta();
            frm.MdiParent = this;
            frm.Nuevo();
            frm.Show();
        }

        private void gestionDeMenudeoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmGestionMenudeo frm = new FrmGestionMenudeo();
            frm.MdiParent = this;
            frm.Show();
        }

        private void clientesToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmCliente frm = new frmCliente();
            frm.MdiParent = this;
            frm.Show();
        }

        private void buscarComprasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmCompra frm = new FrmCompra();
            frm.MdiParent = this;
            frm.Show();
        }

        private void registrarCompraToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmDetalleCompra frm = new FrmDetalleCompra();
            frm.MdiParent = this;
            frm.Nuevo();
            frm.Show();
        }

        private void proveedoresToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            FrmProveedor frm = new FrmProveedor();
            frm.MdiParent = this;
            frm.Show();
        }

        private void cREDITOSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmCredito frm = new frmCredito();
            frm.MdiParent = this;
            frm.Show();
        }

        private void iMPUESTOSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmImpuesto frm = new frmImpuesto();
            frm.MdiParent = this;
            frm.Show();
        }

        private void cATEGORÍASToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmCategoria frm = new FrmCategoria();
            frm.MdiParent = this;
            frm.Show();
        }      

        private void hISTORIALESToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmHistorialVentas frm = new frmHistorialVentas();
            frm.MdiParent = this;
            frm.Show();
        }

        private void sALIRToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            lblHora.Text = DateTime.Now.ToLongDateString()  + "       -      " + DateTime.Now.ToLongTimeString();
        }

        private void salirToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void minimizarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        #endregion

        #region REPORTES

        private DateTime fec1 = DateTime.Now.Date;
        private DateTime fec2 = DateTime.Now.Date;
        //MessageBox.Show("La fecha de inicio debe ser menor a la fecha de término","Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);

        private void ingresosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmIngresosCategorias frm = new frmIngresosCategorias();
            frm.MdiParent = this;
            frm.ObtenerFecha1(fec1.AddDays(-7).Date);
            frm.ObtenerFecha2(fec2.Date);
            frm.Show();
        }

        private void egresosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmEgresosCategorias frm = new frmEgresosCategorias();
            frm.MdiParent = this;
            frm.ObtenerFecha1(fec1.AddDays(-7).Date);
            frm.ObtenerFecha2(fec2.Date);
            frm.Show();
        }

        private void productosTopToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmProductosTop frm = new frmProductosTop();
            frm.MdiParent = this;
            frm.ObtenerFecha1(fec1.AddDays(-7).Date);
            frm.ObtenerFecha2(fec2.Date);
            frm.Show();
        }

        private void productosFaltantesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmProductosFaltantes frm = new frmProductosFaltantes();
            frm.MdiParent = this;
            frm.Show();
        }

        private void capitalInvertidoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmCapitalInvertido frm = new frmCapitalInvertido();
            frm.MdiParent = this;
            frm.Show();
        }

        private void utilidadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmUtilidad frm = new frmUtilidad();
            frm.MdiParent = this;
            frm.ObtenerFecha1(fec1.AddDays(-7).Date);
            frm.ObtenerFecha2(fec2.Date);
            frm.Show();
        }


        #endregion

        private void deudoresToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //var dia = DateTime.Now.Day;

            //if (dia == 15)
            //{
            //    var rpt = MessageBox.Show(this, string.Format("¿Desea ver el reporte de deudores?", "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            //    if (rpt == DialogResult.Yes)
            //    {
            var frm = new frmReporteDeudores();
            frm.MdiParent = this;
            frm.Show();
            //    }
            //}

        }











    }
}
